package net.lovesrc.allin.biz.cpct;

import com.zhouzhou.fastjava.web.WebUtils;
import net.lovesrc.allin.Message;
import net.lovesrc.allin.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/cpct-account")
public class CPCTController extends BaseController {

    @Autowired
    private CPCTService cpctService;

    @PostMapping("/save")
    public Message save(
            String registerUrl,
            String mobile,
            String note
    ) {
        cpctService.save(registerUrl, mobile, note);
        return Message.success();
    }

    @GetMapping("/once")
    public Message once() {

        cpctService.transferEth();
        return Message.success();
    }

    @PostMapping("/new-register")
    public Message newRegister(String promotionCode) {
        execute(() -> {
            try {
                cpctService.newRegisterByPromotionCode(promotionCode);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        return Message.success();
    }

    @PostMapping("/auth-id")
    public Message authId(String mobile) {
        execute(() -> {
            cpctService.idIdentity(mobile);
        });
        return Message.success();
    }

    @GetMapping("/getAgent")
    public String doAgentTest(HttpServletRequest request){
        String agent = WebUtils.getLowerUserAgent(request);
        return agent;
    }
    @GetMapping("/")
    public String dotest(HttpServletRequest request){
        String agent = WebUtils.getLowerUserAgent(request);
        return agent;
    }

}
